package com.molihub.listener;

import com.molihub.utils.LogUtils;
import org.slf4j.Logger;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @ClassName: SessionListener
 * @Description: Session监听器
 * @author: GGBOY
 * @date 2020/1/31 20:27
 * @Version: 1.0
 **/
@WebListener
public class SessionListener implements HttpSessionListener {
    private static Logger logger = LogUtils.getInstance(SessionListener.class);
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        logger.info("创建Session...............");
        HttpSession session = se.getSession();
        logger.info("这个Session中包含的用户是：" + session.getAttribute("loginUser"));
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        logger.info("销毁Session...............");
        HttpSession session = se.getSession();
        logger.info("这个Session中包含的用户是：" + session.getAttribute("loginUser"));
    }
}
